Getting Started with Agentkit on Flow
Agentkit is an ecosystem-agnostic modular developer toolkit that lets you rapidly build, deploy, and iterate on AI agents using pre-configured environments and ready-to-use templates.
In this guide, you'll set up your own custom agent running on Flow's EVM-compatible testnet, powered by Langchain and Anthropic's Claude LLM.
Quickstart - Starting From Scratch
Open your terminal and run:
_10npm create onchain-agent@latest
Follow the interactive setup:
- Type
y
to proceed, then press Enter. - Select your framework: Langchain
- Choose your network: EVM
- Set the custom Chain ID:
545
for Flow Testnet747
for Flow Mainnet
- JSON-RPC endpoint:
_10https://testnet.evm.nodes.onflow.org
Project Setup
Once your scaffold is ready:
_10cd onchain-agent_10npm install
Now open the project in your preferred IDE (e.g. Cursor).
Environment Configuration
- Create a
.env.local
file (or edit the one generated). - Add your API keys (we'll use Anthropic here).
You can also use OpenAI, DeepSeek, or any other supported LLM.
Get Your Anthropic API Key
- Head to Anthropic Console
- Create an account and purchase credits
- Click Create Key, name it, and copy the API key
- Add this to your
.env.local
:
_10ANTHROPIC_API_KEY=your_api_key_here
Wallet Setup with MetaMask
- Add Flow Testnet to MetaMask
- Use the Faucet to fund your wallet
- Get your private key:
- Click the
...
menu in MetaMask > Account Details - Enter your password, copy the private key
- Click the
- Add it to
.env.local
:
_10PRIVATE_KEY=your_private_key_here
Your .env.local
should look something like this:
_10PRIVATE_KEY=..._10ANTHROPIC_API_KEY=...
Now run:
_10mv .env.local .env_10npm run dev
Visit your local server:
_10http://localhost:3000
Configure Your LLM
If your agent doesn't respond yet — no worries! You still need to configure your LLM and client libraries.
Choose a Model
Langchain supports many LLMs (full list here).
For this example, we'll use Anthropic's claude-3-5-haiku-20241022
, a lightweight and affordable model. Alternatively, DeepSeek is highly recommended for budget-friendly usage.
Update create-agent.ts
Change the default model from OpenAI:
_10const llm = new ChatOpenAI({ model: "gpt-4o-mini" });
To Anthropic:
_10import { ChatAnthropic } from "@langchain/anthropic";_10_10const llm = new ChatAnthropic({ model: "claude-3-5-haiku-20241022" });
Install the package:
_10npm install @langchain/anthropic
Configure Flow and Viem Wallet
Update the Faucet Provider Logic
Change this:
_10const canUseFaucet = walletProvider.getNetwork().networkId == "base-sepolia";
To:
_10const canUseFaucet = walletProvider.getNetwork().networkId == "flow-testnet";
Add Flow Context Message to Agent
This gives your agent context about the Flow testnet:
_14const flowContextMessage = canUseFaucet ? `_14 You are now operating on the Flow blockchain testnet using a Viem wallet. Flow is a fast, decentralized, and_14 developer-friendly blockchain designed for NFTs, games, and apps. _14_14 Key facts about Flow:_14 - Flow uses a proof-of-stake consensus mechanism_14 - The native token is FLOW_14 - Flow has a unique multi-role architecture for high throughput_14 - The testnet is EVM-compatible (works with MetaMask + Viem)_14 - RPC URL: https://testnet.evm.nodes.onflow.org_14 - Chain ID: 545_14_14 Your wallet address is \${await walletProvider.getAddress()}._14` : '';
Then inject it into the agent message modifier:
_16agent = createReactAgent({_16 llm,_16 tools,_16 checkpointSaver: memory,_16 messageModifier: `_16 You are a helpful agent interacting with the Flow blockchain testnet using a Viem wallet._16 Flow testnet supports EVM, so you can use Ethereum-compatible tools._16 \${flowContextMessage}_16_16 Before your first action, check the wallet details. If you see a 5XX error, ask the user to try again later._16 If a task is unsupported, let the user know and point them to CDP SDK + Agentkit at:_16 https://docs.cdp.coinbase.com or https://developers.flow.com._16_16 Be concise, helpful, and avoid repeating tool descriptions unless asked._16 `,_16});
You're Done!
You now have a working AI agent connected to Flow testnet using Agentkit!
You can send faucet tokens to your wallet and start testing smart contract interactions or on-chain workflows.
Starter Project
Want to skip the setup?
This starter includes all necessary config to start building immediately on Flow.
Adding AgentKit to an Existing Project
Already have a project and want to add AgentKit? Follow these steps to integrate it into your existing codebase:
Install the Package
Run this command in your project's root directory:
_10npm install onchain-agent@latest
This will:
- Download and install the latest version of the
onchain-agent
package - Add it to the dependencies section of your
package.json
- Update your
node_modules
folder accordingly
Configure Environment
- Create or update your
.env
file with the necessary API keys:
_10PRIVATE_KEY=your_wallet_private_key_10ANTHROPIC_API_KEY=your_anthropic_api_key_10# Or other LLM API keys
- Configure your RPC endpoints for Flow:
_10FLOW_TESTNET_RPC_URL=https://testnet.evm.nodes.onflow.org_10FLOW_MAINNET_RPC_URL=https://mainnet.evm.nodes.onflow.org
Integrate AgentKit in Your Code
Import and configure AgentKit in your application:
_35// Import AgentKit components_35import { _35 createReactAgent, _35 ChatAnthropic _35} from 'onchain-agent';_35import { _35 createWalletClient, _35 http, _35 createPublicClient _35} from 'viem';_35_35// Set up your Flow wallet provider_35const walletClient = createWalletClient({_35 transport: http('https://testnet.evm.nodes.onflow.org'),_35 chain: {_35 id: 545, // Flow Testnet_35 name: 'Flow Testnet',_35 },_35 account: yourPrivateKey_35});_35_35// Configure the LLM_35const llm = new ChatAnthropic({ _35 model: "claude-3-5-haiku-20241022" _35});_35_35// Create your agent_35const agent = createReactAgent({_35 llm,_35 tools: yourSelectedTools,_35 // Additional configuration_35});_35_35// Use the agent in your application_35// ...
Add Specialized Tools (Optional)
To add specialized blockchain tools to your agent:
_22import { _22 viem, _22 ViemToolConfig _22} from 'onchain-agent';_22_22// Configure Viem tools for Flow_22const viemTools = viem.createTools({_22 chain: {_22 id: 545,_22 name: 'Flow Testnet',_22 },_22 transport: http('https://testnet.evm.nodes.onflow.org')_22} as ViemToolConfig);_22_22// Add these tools to your agent_22const agent = createReactAgent({_22 llm,_22 tools: [_22 ...viemTools,_22 // Other tools_22 ],_22});
Resources
Happy hacking on Flow!